package org.jackysoft.opensymphony.workflow.util;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jackysoft.entity.Step;
import org.jackysoft.opensymphony.workflow.Condition;
import org.jackysoft.opensymphony.workflow.JoinNodes;
import org.jackysoft.opensymphony.workflow.WorkflowException;
import org.jackysoft.service.VariableService;
import org.jackysoft.util.StringUtils;



/**
 * 会签所用的condition
 * */
public class DissidentCondition implements Condition {
	private static final Log log = LogFactory.getLog(DissidentCondition.class);

	public boolean passesCondition(Map transientVars, Map args,VariableService vservice)
			throws WorkflowException {
		String first = (String) args.get("firstid");
		
		
		if (!StringUtils.isNotEmpty(first)) {
			log.error("No first stepid/second id setted!");
			return false;
		}
		int i = 0;
		try {
			i = Integer.parseInt(first);
		} catch (NumberFormatException e) {
			log.error(e.getMessage());
			return false;
		} finally {
			log.info("Specify StepId is " + i);
		}
		Step fs = ((JoinNodes) transientVars.get("jn")).getStep(i);
		// log.info(transientVars.get("jn").getClass());
		// log.info("指定步骤的状态 = "+fs.getStatus());
		return "Finished".equals(fs.getStatus());
	}

}
